var _contextPath;
$(document).ready(function() {
	doSearch();
});

/**
 * 判断字符串是否为空
 * 
 * @param str
 * @returns
 */
function isNotBlank(str) {
	if (str && /\S+/.test(str)) {
		return true;
	}
	return false;
}
/**
 * 查询用户列表
 */
function doSearch() {
	var beginTime = $('input[name="beginTime"]').val();
	var endTime = $('input[name="endTime"]').val();
	// if(isNotBlank(beginTime)){
	// beginTime = dateFormatForSearch(beginTime);
	// }
	// if(isNotBlank(endTime)){
	// endTime = dateFormatForSearch(endTime);
	// }
	if (isNotBlank(beginTime) && isNotBlank(endTime) && beginTime > endTime) {
		top.uppShow('开始时间不能大于结束时间');
		return false;
	}
	$("#data_list")
			.datagrid(
					{
						queryParams : {
							beginTime : beginTime,
							endTime : endTime
						},
						columns : [ [
								{
									field : 'ctime',
									title : '日期',
									formatter : function(value, row, index) {
										return (new Date(Number(value)))
												.dateConvert().substr(0, 10);
									}
								},
								{
									field : 'rechargeableCardCreditAmountSum',
									title : '退款汇总',
									align : 'center',
									formatter : function(value, row, index) {
										return -value;
									}
								},
								{
									field : '_oxxx',
									title : '操作',
									align : 'center',
									formatter : function(value, row, index) {
										
										var time = (new Date(Number(row.ctime)))
												.dateConvert().substr(0, 10);
										return '<a style="cursor: pointer;color: red;" onclick="javascipt:findCancelDetails(\''
												+ time + '\');" >明细查看</a>'
									}
								} ] ],
						autoRowHeight : true,
						fitColumns : true,
						pagination : true,
						rownumbers : true,
						singleSelect : true
					});

	// 汇总
	$
			.ajax({
				url : contextPath + '/iccard/rechargecard/totalCancelAmount',
				dataType : "json",
				data : {
					beginTime : beginTime,
					endTime : endTime
				},
				success : function(data) {
					$("#total_cancel_amount").text(
							"退款总额：" + (-(data.totalCancelAmount)));
				}
			});
}

function getContextPath() {
	if ("" == _contextPath) {
		_contextPath = $("#contextPath").val();
	}
	return _contextPath;
}

function findCancelDetails(time) {
	window.location.href = contextPath
			+ "iccard/recharge/rechargecard_findCanceledDetails.jsp?time="
			+ time;
}
